package team.dmh.wx.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import team.dmh.wx.exception.ExceptionEnum;

/**
 * @Auther: Hz1kai
 * @Date: 2018/9/24 16:58
 * @Description:
 */
public class ResultUtils {

    public static Result success() {
        return new Result().success();
    }

    public static Result success(Object data) {
        return new Result().success().data(data);
    }

    public static Result success(String info) {
        return new Result().success().info(info);
    }

    public static Result success(String info, Object data) {
        return new Result().success().info(info).data(data);
    }

    public static Result fail() {
        return new Result().fail();
    }

    public static Result fail(String info, Object data) {
        return new Result().fail().info(info).data(data);
    }

    public static Result fail(String info) {
        return new Result().fail().info(info);
    }

    public static Result success(String info, Object data, String key, Object value) {
        Result resultMap = new Result();
        resultMap.success().info(info).data(data).put(key, value);
        return resultMap;
    }

    public static Result page(IPage page) {
        Result resultMap = new Result();
        resultMap.success();
        //总记录数
        resultMap.put("records", page.getTotal());
        //数据
        resultMap.put("rows", page.getRecords());
        //总页数
        resultMap.put("total", page.getPages());
        //当前页
        resultMap.put("page", page.getCurrent());
        return resultMap;
    }

    public static Result fail(ExceptionEnum exceptionEnum) {
        Result result=new Result().fail().info(exceptionEnum.getMessage());
//        result.put("code",exceptionEnum.getStatus());
        return result;
    }

}
